#include "gameLog.h"
#include <fstream>

using namespace std;

GameLog::GameLog() {
}

void GameLog::Create(string filename) {
	this->logFile = new ofstream(filename.c_str());
	*this->logFile << "<?xml version=\"1.0\" ?>\n";
	*this->logFile << "<gameLog>\n";
}

void GameLog::Close() {
	*this->logFile << "</gameLog>\n";
}

void GameLog::LogPlayers(string playerIdentification[2]) {
	*this->logFile << "	<players>\n";
	*this->logFile << "		<player color=\"0\">" << playerIdentification[0] << "</player>\n";
	*this->logFile << "		<player color=\"1\">" << playerIdentification[1] << "</player>\n";
	*this->logFile << "	</players>\n";
}

void GameLog::StartMovesSection() {
	*this->logFile << "	<moves>\n";
}

void GameLog::EndMovesSection() {
	*this->logFile << "	</moves>\n";
}

void GameLog::LogMove(Move aMove) {
	*this->logFile << "	<move>\n";
		*this->logFile << "		<player>" << aMove.Player << "</player>\n";
		*this->logFile << "		<fitnessComponents>\n";
			*this->logFile << "			<x1>" << aMove.FitnessComponents[0] << "</x1>\n";
			*this->logFile << "			<x2>" << aMove.FitnessComponents[1] << "</x2>\n";
			*this->logFile << "			<x3>" << aMove.FitnessComponents[2] << "</x3>\n";
			*this->logFile << "			<x4>" << aMove.FitnessComponents[3] << "</x4>\n";
			*this->logFile << "			<x5>" << aMove.FitnessComponents[4] << "</x5>\n";
			*this->logFile << "			<x6>" << aMove.FitnessComponents[5] << "</x6>\n";
		*this->logFile << "		</fitnessComponents>\n";
		*this->logFile << "		<fitnessTotal>" << aMove.FitnessTotal << "</fitnessTotal>\n";
	*this->logFile << "	</move>\n";
}

void GameLog::LogWinner(int winner) {
	*this->logFile << "	<winner>" << winner << "</winner>\n";
}